package com.huawei.appmarket.service.installdepend.view.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.HeaderViewListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardkit.widget.CardListAdapter;
import com.huawei.appgallery.foundation.ui.framework.widget.NetworkRemindBar;
import com.huawei.appgallery.foundation.ui.framework.widget.NetworkRemindBar.c;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a;
import com.huawei.appmarket.service.appdetail.view.AppNoContentFragmentProtocol;
import com.huawei.appmarket.service.installdepend.bean.GetDetailByIdResBean;
import com.huawei.appmarket.service.installdepend.bean.GetDetailByIdResBean$DetailInfoBean;
import com.huawei.appmarket.service.installdepend.view.fragment.protocol.InstallDependFragmentProtocol;
import com.huawei.appmarket.service.installdepend.view.fragment.protocol.InstallDependFragmentProtocol.Request;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.List;
import o.cia;
import o.cih;
import o.cii;
import o.cip;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cvt;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.drd;
import o.dvq;
import o.eaj;
import o.eaq;
import o.ear;
import o.eib;
import o.ActivityUtil;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.FragmentTransaction;

public class InstallDependFragment extends BaseListFragment<InstallDependFragmentProtocol> implements c {
    private BroadcastReceiver ʹ = new BroadcastReceiver(this) {
        final /* synthetic */ InstallDependFragment ˏ;

        {
            this.ˏ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            if (this.ˏ.ͺˎ != null) {
                CardListAdapter cardListAdapter;
                if (this.ˏ.ͺˎ.getAdapter() instanceof HeaderViewListAdapter) {
                    cardListAdapter = (CardListAdapter) ((HeaderViewListAdapter) this.ˏ.ͺˎ.getAdapter()).getWrappedAdapter();
                } else {
                    cardListAdapter = (CardListAdapter) this.ˏ.ͺˎ.getAdapter();
                }
                if (cardListAdapter != null && cardListAdapter.getCount() > 0) {
                    cardListAdapter.notifyDataSetChanged();
                }
            }
        }
    };
    private FrameLayout ʼ;
    private final SafeBroadcastReceiver ʽ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ InstallDependFragment ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (context == null || intent == null) {
                Logger.e("InstallDependFragment", "onReceive, context = " + context + ", intent = " + intent);
                return;
            }
            if ("android.intent.action.PACKAGE_ADDED".equals(intent.getAction()) && ActivityUtil.ˋ(context)) {
                String ͺॱ = this.ˋ.ˊ.ͺॱ();
                String ˋᐝ = this.ˋ.ˊ.ˋᐝ();
                String ˍ = this.ˋ.ˊ.ˍ();
                String ˎˎ = this.ˋ.ˊ.ˎˎ();
                RpkInfo ˏˏ = this.ˋ.ˊ.ˏˏ();
                String ʼ = dof.ʼ(intent.getDataString());
                String str = "";
                if (ʼ.length() >= 9) {
                    str = ʼ.substring(8);
                }
                if (str.equals(ˍ)) {
                    ear.ˋ(ͺॱ, ˎˎ, ˋᐝ, ˏˏ, context);
                }
            }
        }
    };
    private Request ˊ;
    private TextView ˋ;
    private TextView ˎ;
    private InstallDependFragmentProtocol ˏ;
    protected NetworkRemindBar ॱ;
    private LinearLayout ॱॱ;
    private Context ᐝ;
    private cip ﾞ;
    private boolean ﾟ = false;

    public void ˏ(Bundle bundle) {
        ᐝʼ();
        super.ˏ(bundle);
    }

    public int ߵ() {
        return h.ㆍॱ;
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        eib.ॱ(ContentManager.getInstant().getContext());
        ViewGroup viewGroup2 = (ViewGroup) super.ˋ(layoutInflater, viewGroup, bundle);
        this.ˎ = (TextView) viewGroup2.findViewById(j.ˡॱ);
        this.ˋ = (TextView) viewGroup2.findViewById(j.ˑʼ);
        this.ʼ = (FrameLayout) viewGroup2.findViewById(j.ˈॱ);
        this.ॱॱ = (LinearLayout) viewGroup2.findViewById(j.ˏᵎ);
        this.ˊʼ = this.ᐝ.getResources().getString(n.ˋﾟ);
        if (bundle != null) {
            this.ˎ.setText(bundle.getString("install.depend.notice"));
            this.ˋ.setText(bundle.getString("install.depend.notice2"));
        }
        if (ʼʻ()) {
            ˋॱ(true);
            if (!(this.ߴ == null || this.י.ˊॱ() != 0 || this.י.ᐝ())) {
                this.ߴ.setVisibility(0);
            }
        } else {
            this.ﾞ = new cip(false);
            viewGroup2.addView(this.ﾞ.ˏ(layoutInflater), 0);
            this.ﾞ.ˋ(new OnClickListener(this) {
                final /* synthetic */ InstallDependFragment ॱ;

                {
                    this.ॱ = r1;
                }

                public void onClick(View view) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("InstallDependFragment", "loadingCtl onClick will onLoadingRetry()");
                    }
                    this.ॱ.ʼᐝ();
                }
            });
            this.ﾞ.ˏ();
            ˋॱ(false);
            if (this.ﾟ) {
                ʿˊ();
            }
        }
        ˉॱ();
        return viewGroup2;
    }

    public void ˋ(Bundle bundle) {
        super.ˋ(bundle);
        bundle.putCharSequence("install.depend.notice", this.ˎ.getText());
        bundle.putCharSequence("install.depend.notice2", this.ˋ.getText());
    }

    public void ˋ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        super.ˋ(viewGroup, layoutInflater);
        ˎ(viewGroup);
        this.ॱ = (NetworkRemindBar) viewGroup.findViewById(j.ᐝי);
        this.ॱ.setNetworkRemindBarListener(this);
        this.ॱ.ˋ();
    }

    public void ᐝʼ() {
        this.ˏ = (InstallDependFragmentProtocol) ˆ();
        this.ˊ = this.ˏ.ˋ();
        this.ᐝ = ॱˋ();
    }

    public void ʼᐝ() {
        super.ʼᐝ();
        this.ͺˎ.ʻ();
        ʿˊ();
    }

    public cia ˊ(Context context) {
        return eaq.ˊ().ˎ(context);
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        list.add(new eaj(this.ˊ.ˍ()));
    }

    private boolean ˏ(int i, int i2) {
        Logger.ˎ("InstallDependFragment", "OnCompleted,isSucc responseCode:" + i + ", rtnCode:" + i2);
        return i == 0 && i2 == 0;
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        if (this.ͺˎ != null) {
            this.ͺˎ.setmPullRefreshing(false);
        }
        ResponseBean responseBean = (GetDetailByIdResBean) bVar.ˋ;
        if (bVar.ˋ.getRtnCode_() != 0) {
            AppNoContentFragmentProtocol.Request request = new AppNoContentFragmentProtocol.Request();
            request.ˎ(false);
            request.ˊ(ॱ(n.ﹳॱ));
            cjo appNoContentFragmentProtocol = new AppNoContentFragmentProtocol();
            appNoContentFragmentProtocol.ˋ(request);
            Fragment ˊ = cjk.ˎ().ˊ(new cjm("appnocontent.fragment", appNoContentFragmentProtocol));
            this.ʼ.removeAllViews();
            try {
                FragmentTransaction ˊ2 = ॱᐝ().ˊ();
                ˊ2.ˋ(j.ˈॱ, ˊ);
                ˊ2.ˋ();
            } catch (ArrayIndexOutOfBoundsException e) {
                Logger.ˋ("InstallDependFragment", e.toString());
            }
        }
        if (ˏ(responseBean.getResponseCode(), responseBean.getRtnCode_())) {
            if (!(ʼʻ() || this.ﾞ == null)) {
                this.ﾞ.onEvent(0);
                ˋॱ(true);
                this.ﾞ = null;
            }
            ॱˋ(true);
            if (responseBean.getResponseType() != a.ˏ) {
                long ˌ = this.ˊ.ˌ();
                List ˏ = responseBean.ˏ();
                if (!(ˏ == null || ˏ.isEmpty())) {
                    GetDetailByIdResBean$DetailInfoBean getDetailByIdResBean$DetailInfoBean = (GetDetailByIdResBean$DetailInfoBean) ˏ.get(0);
                    eaq.ˊ().ˎ(this.י, getDetailByIdResBean$DetailInfoBean, ˌ);
                    String ˏॱ = getDetailByIdResBean$DetailInfoBean.ˏॱ();
                    try {
                        int parseInt = Integer.parseInt(ˏॱ);
                        drd.ˏ(this.ˊ.ˍ(), ˏॱ);
                        if (ˌ <= ((long) parseInt)) {
                            this.ˎ.setText(this.ᐝ.getResources().getString(n.ˋꞌ));
                        } else {
                            this.ˎ.setText(this.ᐝ.getResources().getString(n.ˋˈ, new Object[]{Integer.valueOf(1)}));
                            this.ˋ.setVisibility(0);
                            this.ˋ.setText(this.ᐝ.getResources().getString(n.ˋꜞ, new Object[]{Integer.valueOf(2)}));
                        }
                    } catch (Exception e2) {
                        Logger.e("InstallDependFragment", "onResponse: " + e2.toString());
                    }
                }
            }
        } else {
            ˏ(responseBean.getResponseType(), ˎ(responseBean), this.ॱ);
        }
        return false;
    }

    protected int ˎ(ResponseBean responseBean) {
        return responseBean.getResponseCode();
    }

    public void ˏ(a aVar, int i, NetworkRemindBar networkRemindBar) {
        Logger.ˎ("InstallDependFragment", "OnCompleted,errorDeal:" + "InstallDependFragment" + ", rtnType:" + aVar);
        if (aVar != a.ˋ) {
            this.ﾟ = true;
            if (this.ﾞ != null) {
                this.ﾞ.onEvent(i);
            } else {
                ˎ(networkRemindBar, i);
            }
        }
    }

    private void ˎ(NetworkRemindBar networkRemindBar, int i) {
        if (networkRemindBar == null) {
            return;
        }
        if (3 == i) {
            networkRemindBar.ॱ();
        } else {
            networkRemindBar.ˏ();
        }
    }

    private void ˉॱ() {
        try {
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addDataScheme(HiAnalyticsConstant.BI_KEY_PACKAGE);
            intentFilter.addAction("android.intent.action.PACKAGE_ADDED");
            this.ᐝ.registerReceiver(this.ʽ, intentFilter);
        } catch (Throwable e) {
            Logger.ˋ("InstallDependFragment", "registerBroadCast, e", e);
        }
    }

    private void ˊʻ() {
        try {
            ॱˋ().unregisterReceiver(this.ʽ);
        } catch (Throwable e) {
            Logger.ˋ("InstallDependFragment", "unregisterBroadCast, e: ", e);
        }
    }

    public void ᐝ() {
        super.ᐝ();
        ˊʻ();
    }

    public void ˋॱ(boolean z) {
        if (this.ॱॱ != null) {
            if (z) {
                this.ॱॱ.setVisibility(0);
            } else {
                this.ॱॱ.setVisibility(8);
            }
        }
        if (this.ߴ == null) {
            return;
        }
        if (z) {
            this.ߴ.setVisibility(8);
        } else {
            this.ߴ.setVisibility(0);
        }
    }

    public void ﾟॱ() {
        if (this.ﾞ != null) {
            this.ﾞ.ˊ();
        }
        ʼᐝ();
    }

    public void ﹶ() {
    }

    public void ʳ() {
    }

    public void ˏ(int i, cih o_cih) {
        if (i == 0) {
            BaseCardBean baseCardBean = (BaseDistCardBean) o_cih.ˌ();
            if (baseCardBean == null) {
                return;
            }
            if ((baseCardBean.ॱॱ() != null || baseCardBean.ˑ() != null) && baseCardBean.ॱॱ() != null && !cii.ˊ().ˊ(ॱˋ(), baseCardBean)) {
                ˊ(baseCardBean);
            }
        }
    }

    public void ˊ(BaseCardBean baseCardBean) {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        appDetailActivityProtocol.ˏ(new AppDetailActivityProtocol.Request(baseCardBean.ॱॱ(), null));
        cjm o_cjm = new cjm("appdetail.activity", appDetailActivityProtocol);
        if (this.ᐝ != null) {
            cjk.ˎ().ˋ(this.ᐝ, o_cjm);
        }
    }

    public void ˌॱ() {
        super.ˌॱ();
        ActivityUtil.registerReceiver(ॱˋ(), new IntentFilter(dvq.ˊ()), this.ʹ);
    }

    public void ˋʼ() {
        super.ˋʼ();
        ActivityUtil.unregisterReceiver(ॱˋ(), this.ʹ);
    }
}
